<template>
  <view class="my_userInfo_container">
    <!-- 头像昵称区域 -->
    <view class="top_box">
      <image :src="userInfo.avatarUrl" class="avater"></image>
      <view  class="nickname">{{userInfo.nickName}}</view>
    </view>
    
    <!-- 面板列表区域 -->
    <view class="panel_list">
      <!-- 第一个面板 -->
      <view class="panel">
        <!-- panel的主体区域 -->
        <view class="panel_body">
          <!-- panel的item项 -->
          <view class="panel_item">
            <text>8</text>
            <text>收藏的店铺</text>
          </view>
          <view class="panel_item">
            <text>14</text>
            <text>收藏的商品</text>
          </view>
          <view class="panel_item">
            <text>18</text>
            <text>关注的商品</text>
          </view>
          <view class="panel_item">
            <text>84</text>
            <text>足迹</text>
          </view>
        </view>
      </view>
      
      <!-- 第二个面板 -->
      <view class="panel">
        <!-- panel的标题区域 -->
        <view class="panel_title">我的订单</view>
        <!-- panel的主体区域 -->
        <view class="panel_body">
          <!-- panel的item项 -->
          <view class="panel_item">
            <image src="/static/my-icons/icon1.png" class="icon"></image>
            <text class="tips_text">待付款</text>
          </view>
          <view class="panel_item">
            <image src="/static/my-icons/icon2.png" class="icon"></image>
            <text>待收货</text>
          </view>
          <view class="panel_item">
            <image src="/static/my-icons/icon3.png" class="icon"></image>
            <text>退款/退货</text>
          </view>
          <view class="panel_item">
            <image src="/static/my-icons/icon4.png" class="icon"></image>
            <text>全部订单</text>
          </view>
        </view>
      </view>
      
      <!-- 第三个面板 -->
      <view class="panel">
        <view class="panel_list_item">
          <text class="item_left">收货地址</text>
          <uni-icons type='arrowright' size='15' class='item_right'></uni-icons>
        </view>
        <view class="panel_list_item">
          <text class="item_left">联系客服</text>
          <uni-icons type='arrowright' size='15' class='item_right'></uni-icons>
        </view>
        <view class="panel_list_item">
          <text class="item_left" @click='logout'>退出登录</text>
          <uni-icons type='arrowright' size='15' class='item_right'></uni-icons>
        </view>
      </view>
  
    </view>
    
  </view>
</template>

<script>
  import { mapState, mapMutations } from 'vuex'
  export default {
    name:"my-userInfo",
    computed: {
      ...mapState('m_user', ['userInfo'])
    },
    data() {
      return {
        
      };
    },
    methods: {
      ...mapMutations('m_user',['upateUserInfo','updateToken','updateAddress']),
      logout() {
        // 询问用户是否确认退出登录
        uni.showModal({
          title: '提示',
          content:'确认退出登录吗?',
          success: res => {
            // console.log(res)
            if (res.confirm) {
              // 清空vuex中的数据: userinfo、token 和 address
              this.upateUserInfo({})
              this.updateToken('')
              this.updateAddress({})
            }
          },
          fail: err => {
            // console.log(err)
            return err
          }
        })
      }
    }
  }
</script>

<style lang="scss">
.my_userInfo_container {
  height: 100%;
  background-color: #f4f4f4;
  .top_box {
    background-color: #C00000;
    height: 400rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .avater {
      height: 90px;
      width: 90px;
      border-radius: 50%;
      border: 2px solid #fff;
      box-shadow: 0 1px 5px black;
    }
    .nickname {
      margin-top: 10px;
      color: #fff;
      font-weight: 700;
    }
  }
  .panel_list {
    padding: 0 10px;
    position: relative;
    top: -10px;
    .panel {
      border-radius:  3px;
      margin-bottom: 8px;
      background-color: #fff;;
      .panel_title {
      font-size: 15px;
       padding-left: 10px;
       height: 45px;
       line-height: 45px;
       border-bottom: 1px solid #efefef;
      }
      .panel_list_item {
        padding: 0 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        line-height: 45px;
        font-size: 15px;
      }
      .panel_body {
        display: flex;
        justify-content: space-around;
        .panel_item {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          align-items: center;
          padding: 10px 0;
          font-size: 13px;
          .icon {
            width: 35px;
            height: 35px;
          }
        }
      }
    }
  }
}
</style>